{*
  Object Pascal text report manipulation routines
  @Author  Maciej Zagozda (1998-2008)
  @Licence Microsoft Reciprocal License (Ms-RL)
  @Website http://www.codeplex.com/intelitechdelphirtns/
  @Version 2008/04/20 Added documentation support
}

unit ReportRoutines;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms;

function CloseLines: Boolean;
function InitLines: Boolean;
function WriteLine( strnString: AnsiString ): Boolean;

var
  fileX: TextFile;

implementation

uses
  DateRoutines,
  FileRoutines,
  FolderRoutines,
  IntegerRoutines,
  MessageRoutines,
  StringRoutines,
  SystemRoutines;

function InitLines: Boolean;
var
  strnFileName: AnsiString;
begin
  Result := True;
  strnFileName := Application.ExeName + '.' + FormatDateTime( 'yyyymmddhhnnss', Now ) + '.log';
  try
    AssignFile( fileX, strnFileName );
    Rewrite( fileX );
  except
    Result := False;
  end;//try
end;

function CloseLines: Boolean;
begin
  Result := True;
  try
    if AnsiPos( '/NOLOG', ParamStr( 1 )) = 0 then
    begin
      CloseFile( fileX );
    end;//if
  except
    Result := False;
  end;//try
end;//

function WriteLine( strnString: AnsiString ): Boolean;
begin
  Result := True;
  if AnsiPos( '/NOLOG', ParamStr( 1 )) = 0 then
  begin
    {frmDefaultInterface.memDebug.Lines.Add( strnString );}
    try
      WriteLn( fileX, strnString );
      Flush( fileX );
    except
      Result := False;
    end;//try
  end;//if
end;

end.
 
